package dispatch

import (
	"context"
	"order_srv/handler/dispatch/internal"
	"time"
)

// FindBestDriver 统一门面，方便在 DAO 中调用
func FindBestDriver(ctx context.Context, cityId uint32, startLng, startLat float64, serviceTime time.Time, params Params) (uint32, string, error) {
	// 候选池：优先 GEO，缺失时可回落为空（让上层降级）
	candidates, _ := internal.QueryNearbyDrivers(ctx, cityId, startLng, startLat, params.MaxDistanceKM)
	dec, err := NewEngine().Dispatch(ctx, params, startLng, startLat, serviceTime, candidates)
	if err != nil {
		return 0, "", err
	}
	return dec.DriverId, dec.Reason, nil
}
